package com.howells.time.module.setting.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Switch;
import android.widget.TextView;

import com.howells.time.R;
import com.howells.time.base.activity.BaseActivity;
import com.howells.time.base.utils.SharedPrefsUtil;
import com.howells.time.base.utils.StatusBarUtil;
import com.howells.time.base.utils.ToastShow;
import com.howells.time.module.UIHelper;
import com.howells.time.module.setting.presenter.SettingPresenter;
import com.howells.time.module.setting.presenter.SettingPresenterImp;

/**
 * Created by Administrator on 2016.5.8.
 */
public class SettingActivity extends BaseActivity implements SettingView{

    private SettingPresenter settingPresenter;
    private Switch mServiceSwitch;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        StatusBarUtil.setColor(this,0);
        settingPresenter=new SettingPresenterImp(this);

        mServiceSwitch= (Switch) findViewById(R.id.serviceswitch);
        mServiceSwitch.setChecked(SharedPrefsUtil.getValue(getApplicationContext(),"config","service",true));

        init();
    }

    private void init() {
   /*     TextView cache= (TextView)findViewById(R.id.set_cache_size);
        String size= FileSizeUtils.getAutoFileOrFilesSize(Environment.getExternalStorageDirectory()+FileUtil.MEDIA_FILE_DIR);
        cache.setText(size);*/
        ((TextView)findViewById(R.id.top_pannel_title)).setText("设置");
    }

    public void  onClick(View view){
        switch (view.getId()){
            case R.id.top_pannel_back:
                finish();
                break;
            case R.id.clearcache:
                /*   FileUtils.RecursionDeleteFile(new File(Environment.getExternalStorageDirectory()+FileUtil.MEDIA_FILE_DIR));
                TextView cache= (TextView) view.findViewById(R.id.set_cache_size);
                String size= FileSizeUtils.getAutoFileOrFilesSize(Environment.getExternalStorageDirectory()+FileUtil.MEDIA_FILE_DIR);
                cache.setText(size);*/
                ToastShow.ToastShort(this, "清除缓存成功!");
                break;
            case R.id.newversion:
                ToastShow.ToastShort(this,"已经是最新版本");
                break;
            case R.id.serviceswitch:
           /*     Intent intent=new Intent(this, TimeService.class);
                if(mServiceSwitch.isChecked()){
                    SharedPrefsUtil.putValue(getApplicationContext(),"config","service",true);
                    ToastShow.ToastShort(this,"定时推送服务开启");
                    startService(intent);
                }else {
                    SharedPrefsUtil.putValue(getApplicationContext(),"config","service",false);
                    ToastShow.ToastShort(this,"定时推送服务关闭");
                    stopService(intent);
                }*/
                break;
            case R.id.setServer:
                UIHelper.jumpSetServer(this);
                break;
        }
    }
}
